import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  // 默认路由
  routes: constantRoutes
}
const mutations = {
  setRoute(state, newRoute) {
    state.routes = [...constantRoutes, ...newRoute]
  }
}
const actions = {
  filterRoutes(context, menus) {
    // menus: ["settings","permissions"]
    // asyncRoutes  [{path: 'setting',name: 'setting'},{}]
    const routes = []
    menus.forEach((key) => {
      routes.push(...asyncRoutes.filter((item) => item.name === key))
    })
    context.commit('setRoute', routes)
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
